<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
	</head>
	<body>
		<script>
			//数组array
			//储存所有内容的一种方式
			
			//1.自变量方式创建
			var arr = ["张三",18,"李四",20];//合法
			console.log(arr);//Array(4)
			
			//new关键字
			var arr = new Array("张三",18,"李四",20);
			console.log(arr);
			
			//访问数组
			var arr = ["热巴","吴磊","杨洋"];
			console.log(arr[0]);//访问下标
			
			//练习：创建一个数组，里面存放的是星期，然后控制台打印输出星期二
			var arr = ["星期一","星期二","星期三","星期四","星期五","星期六","星期日"];
			console.log(arr[1]);//访问下标
			
			//练习：控制台依次打印星期数(遍历数组)
			var arr = ["星期一","星期二","星期三","星期四","星期五","星期六","星期日"];
			for (var i = 0;i < arr.length;i++){
				console.log(arr[i]);//循环访问下标
			}
			
			//练习：求数组[2,6,7,4]的和与平均值
			var sum = 0;
			var arr = [2,6,7,4];
			for (var i = 0;i < arr.length;i++){
				sum += arr[i];
			}
			var avg = sum / arr.length;
			console.log(sum,avg)//19 | 4.75
			
			//练习：数组[2,6,3,76,52,25,7]的最大值(取部分冒泡排序思想)
			var max = arr[0];//最大值先取数组下标0，能省一点内存
			var arr = [2,6,3,76,52,25,7];
			for (var i = 1;i < arr.length;i++){//i没必要从0开始
				if (arr[i]>max) {
					max = arr[i];//第一步会将下标1与下标0比较
				}
			}
			console.log(max);
			
			//新增数组(扩充内容)(改长度)
			var arr = [];
			arr[0] = 1;//直接增加元素
			console.log(arr,arr.length);
			arr[1] = 2;
			console.log(arr,arr.length);//length长度为2
			
			arr.length = 7;//[1,2,,,,,,]
			console.log(arr,arr.length);//[1,2,empty x5] length=7
			
			//练习：创建一个数组，存放整数1-10；(改长度)
			var arr = [];
			for (var i = 0;i < 10;i++){
				arr[i] = i+1;//直接新增
			}
			console.log(arr);
			
			//练习，创建一个数组2,0,6,1,77,3,52,1,25,7，然后输出大于10的数，组成新的数组
			var arr = [2,0,6,1,77,3,52,1,25,7];
			var arr10 = [];
			var j = 0;
			for (var i = 0;i < arr.length;i++){
				if (arr[i]>10){
					arr10[j++] = arr[i];//第一次听说这个操作，竟然真的能用
					// j++;
				}
			}
			console.log(arr10);
			
			//函数（封装后重复执行一段代码）
			//练习：求任意两个数之间的和
			function getSumTest(a,b){
				var sum = 0;
				for (a;a<=b;a++){
					sum += a;
				}
				return sum;//返回值
			}
			console.log(getSumTest(1,100));//调用
		</script>
	</body>
</html>